import urllib.parse

from ...base.client import Client
from ...base.helpers import sp_endpoint
from ...utils.load_all_pages import fetch_all_pages_with_delay


class Products(Client):
    sbu_path = 'product'

    # version = 'v2'  # 如果后续版本变化，加上version并且sp_endpoint带上/<version>，如get_product_list接口所示

    @sp_endpoint(f'/<version>/{sbu_path}/pagelist')
    def get_product_list(self, **kwargs):
        return self._request(kwargs.pop('path'), data={**kwargs})

    @sp_endpoint(f'/{sbu_path}/update')
    def update_product(self, **kwargs):
        return self._request(kwargs.pop('path'), data={**kwargs})

    @sp_endpoint(f'/{sbu_path}/batchCreate')
    def batch_create_product(self, **kwargs):
        return self._request(kwargs.pop('path'), data={**kwargs})

    @fetch_all_pages_with_delay(delay=1.5)
    def all_page(self, **kwargs):
        return self.get_product_list(**kwargs)
